<template>
<view>
	<view class="header">仓库盘点</view>
	<view class="table">
		<table border="0" width="95%" cellspacing="0" cellpadding="0">
			<tr>
				<th>商品名称</th>
				<th>现有库存</th>
				<th>实际库存</th>
				<th>货损</th>
			</tr>
			<tr v-for="(item,index) in list" :key="index">
				<td class="td1">{{item.name}}</td>
				<td class="td2">{{item.num}}</td>
				<td class="td2"><input type="number" :value="item.true_num" @input="inc" :data-index="index"></td>
				<td class="td2">{{item.loss_num}}</td>
			</tr>
		</table>
	</view>
	<button class="buttonClass" @click="add">确定</button>
</view>
</template>
<script>
import request from '@/util/request.js'
export default {
	data() {
		return {
			//oaRole 1:店长2:员工3:商户
			list:[]
		}
	},
	onLoad:function(e){
		uni.showLoading({
		    title: '加载中'  
		});
		this.getList();
	},
	methods: {
		getList:function(){
			var data = {
				oa_id:uni.getStorageSync('oa_id')
			}
			var that = this
			request({
				url: 'manage/goods/all',
				method: 'get',
				data:data,
				success: (res) => {
					uni.hideLoading();
					that.list = res.data.data
				},
			})
		},
		inc:function(e){
			let index = e.currentTarget.dataset.index
			let value = e.detail.value
			this.list[index].true_num = value
			this.list[index].loss_num = this.list[index].num - value
			this.$forceUpdate();
		},
		add:function(){
			var that = this
			request({
				url: 'manage/goods/sheet',
				method: 'post',
				data:this.list,
				success: (res) => {
					if(res.data.code == 1){
						uni.showToast({
							title:'盘点成功',
							icon: 'success',
							duration: 2000,
							success() {
								setTimeout(function(){
									uni.navigateBack()
								}, 2000);
							}
						})
					}else{
						uni.showToast({
							title: res.data.msg,
							icon: "none", 
							position:'bottom',
						});
						return;
					}
				},
			})
		}
	},
}
</script>
<style>
.header{
    width:100%;
    height:80rpx;
    line-height: 80rpx;
    text-align: center;
    background:#00b300;
    color:#fff;
}
.table{
	width:100%;
	padding:10rpx 20rpx 120rpx 20rpx;
}
table{
	margin-top:30rpx;
}
td{
	border:1rpx solid #C8C7CC;
	text-align: center;
	height:70rpx;
	line-height:70rpx;
}
th{
	border:1rpx solid #C8C7CC;
	text-align: center;
	height:70rpx;
	line-height:70rpx;
}
.td1{
	width:40%;
}
.td2{
	width:20%;
}

/* input{
	border-bottom: 1rpx dashed #000000;
} */
</style>